package com.corpdata.app.project.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.corpdata.app.project.entity.ProjectInfo;
import com.corpdata.app.project.service.ProjectInfoService;
import com.corpdata.app.project.service.ProjectSetService;
import com.corpdata.app.project.service.ProjectTeamService;
import com.corpdata.common.domain.DataGridRequestDTO;
import com.corpdata.common.result.Result;
import com.corpdata.common.upload.service.SysAttachmentService;
import com.corpdata.common.utils.CorpdataUtil;
import com.corpdata.core.base.BaseController;
import com.corpdata.system.log.OptLog;
import com.corpdata.system.log.OptLogConstant;
import com.corpdata.system.log.WebLog;
import com.corpdata.system.log.entity.OptLogger;

/**
 * 分店表
 * 
 * @author wu
 * @email 64088839@qq.com
 * @date 2018-06-08 15:23:00
 */
 
@Controller
@RequestMapping("app/project")
public class ProjectInfoController extends BaseController{

	@Autowired
	private ProjectInfoService projectInfoService;
	
	@Autowired
	private ProjectSetService ProjectSetService;
	
	@Autowired
	private SysAttachmentService sysAttachmentService;
	
	@Autowired
	private ProjectTeamService projectTeamService;
	
	//新增页面
	@GetMapping("/add")
	public String add(ModelMap map){
		map.put("id", CorpdataUtil.getUUID());
		return "app/project/project_add";
	}
	
	//保存数据
	@WebLog()
	@ResponseBody
	@RequestMapping("/save")
	@OptLog(info=OptLogConstant.INFO_ADD+"分店",module="分店")
	public Result save(ProjectInfo record,String teamUserids,String teamUserid,String fileId){
		return projectInfoService.insert(record, teamUserids, teamUserid,fileId);
	}
	
	//编辑页面
	@RequestMapping("/edit/{id}")
	public String edit(@PathVariable("id") String id,ModelMap map){
		map.put("record", projectInfoService.findById(id));
		return "app/project/projectInfo_edit";
	}
	
	//更新数据
	@WebLog()
	@ResponseBody
	@RequestMapping("/update")
	@OptLog(info=OptLogConstant.INFO_MOF+"分店",module="分店")
	public Result update(ProjectInfo record,String fileId,String sysAttachmentPortraitId){
		return projectInfoService.update(record,fileId,sysAttachmentPortraitId);
	}
	
	//删除
	@WebLog()
	@ResponseBody
	@PostMapping("/delete")
	@OptLog(info=OptLogConstant.INFO_DEL+"分店",module="分店")
	public Result delete(String id){
		return projectInfoService.deleteById(id);
	}
	
	//批量删除
	@WebLog()
	@ResponseBody
	@PostMapping("/deletes")
	public Result deletes(@RequestParam("ids[]") String[] ids){
		return projectInfoService.deleteByIds(ids);
	}
	
	//详情页面
	@GetMapping("/details/{id}")
	public String details(ModelMap map,@PathVariable("id") String id){
		map.put("record", projectInfoService.findById(id));
	    return "app/project/projectInfo_details";
	}
	
	//列表页面
	@GetMapping("/list")
	public String list(){
	    return "app/project/project_list";
	}
		
	//首页页面
	@GetMapping("/index/{id}")
	public String index(ModelMap map,@PathVariable("id") String id){
		map.put("id", id);
	    return "app/project/project_index";
	}
	//首页列表页面
	@GetMapping("/indexSecond/{projectId}")
	public String indexSecond(ModelMap map,@PathVariable("projectId") String projectId){
		map.put("projectId", projectId);
		map.put("record", projectInfoService.findById(projectId));
		map.put("teams", projectTeamService.selectAll(projectId, null));
	    return "app/project/project_second";
	}
	//场地页面
		@GetMapping("/fieldManage")
		public String field(){
		    return "app/project/field/project_fieldManage";
		}
	//设置页面
	@GetMapping("/setting")
	public String setting(){
	    return "app/project/setting/project_set";
	}
	//设置权限页面
	@GetMapping("/setPower")
	public String setPower(){
	    return "app/project/setting/setting_power";
	}
	//设置基本页面
	@GetMapping("/setBasic/{id}")
	public String setBasic(ModelMap map,@PathVariable("id") String id){
		map.put("projectInfo", projectInfoService.findById(id));
	    return "app/project/setting/setting_basic";
	}
	//设置楼层页面
	@GetMapping("/setFloor/{id}")
	public String setFloor(ModelMap map,@PathVariable("id") String id){
		map.put("projectId", id);
	    return "app/project/setting/setting_floor";
	}
	//设置会议室设置页面
	@GetMapping("/setRoomset/{id}")
	public String setRoomset(ModelMap map,@PathVariable("id") String id){
		map.put("projectId", id);
		map.put("set", ProjectSetService.findById(id));
	    return "app/project/setting/setting_roomset";
	}
	//设置会议室设置页面
	@GetMapping("/setPosset/{id}")
	public String setPosset(ModelMap map,@PathVariable("id") String id){
		map.put("projectId", id);
	    return "app/project/setting/setting_posset";
	}
	//列表数据
	@ResponseBody
	@RequestMapping("/listdata")
	public String findByPage(DataGridRequestDTO dgRequest){
		return projectInfoService.findByPage(dgRequest);
	}
}
